package sendMessage;

import java.io.IOException;
import java.net.*;
import java.util.Scanner;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        //聊天室发送端
        //1.创建对象
        DatagramSocket ds = new DatagramSocket(1001);
        //2.获取数据并打包

        while (true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("输入框: ");
            String str = sc.nextLine();
            if("88".equals(str)){
                break;
            }
            byte[] bytes = str.getBytes();
            //3.发送数据
            InetAddress address = InetAddress.getByName("Jack");
            int port = 10011;
            DatagramPacket dp = new DatagramPacket(bytes,bytes.length,address,port);
            ds.send(dp);
        }


        //4.释放资源
        ds.close();


    }
}
